//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Common Core Extensions
//===============================================================================

using System;
using System.ComponentModel;

namespace EntLibContrib.Common.Configuration.Design
{
	/// <summary>
	/// Type Method Name type to hold the two string components that make up a type method name
	/// </summary>
	/// <remarks>A type method name is the combination of a type name and a method name.</remarks>
	[TypeConverter(typeof(TypeMethodNameConverter))]
	public class TypeMethodName : ITypeMethodName
	{
		#region Fields
		private string typeName;
		private string methodName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the name of the type.
		/// </summary>
		/// <value>The name of the type.</value>
		[ReadOnly(true)]
		[CommonDescription("TypeNameDescription")]
		public string TypeName
		{
			get
			{
				return this.typeName;
			}
			set
			{
				if (!String.IsNullOrEmpty(value))
					this.typeName = value.Trim();
			}
		}

		/// <summary>
		/// Gets or sets the name of the method.
		/// </summary>
		/// <value>The name of the method.</value>
		[ReadOnly(true)]
		[CommonDescription("MethodNameDescription")]
		public string MethodName
		{
			get
			{
				return this.methodName;
			}
			set
			{
				if (!String.IsNullOrEmpty(value))
					this.methodName = value.Trim();
			}
		}
		#endregion
			
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="TypeMethodName"/> class.
		/// </summary>
		public TypeMethodName() : this (String.Empty, String.Empty)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TypeMethodName"/> class.
		/// </summary>
		/// <param name="typeName">Name of the type.</param>
		/// <param name="methodName">Name of the method to use.</param>
		public TypeMethodName(string typeName, string methodName)
		{
			this.typeName = typeName;
			this.methodName = methodName;
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Determines whether the specified type method name is null or empty.
		/// </summary>
		/// <param name="typeMethodName">The type method name.</param>
		/// <returns>
		/// 	<c>true</c> if the specified type method name is null or empty; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsNullOrEmpty(TypeMethodName typeMethodName)
		{
			return (String.IsNullOrEmpty(typeMethodName.TypeName) && String.IsNullOrEmpty(typeMethodName.MethodName));
		}
		#endregion
	}
}
